package com.sch.www.ele.services.impl;


import com.sch.www.codeGenerator.base.BaseServicesSimpleImp;
import com.sch.www.codeGenerator.base.CustomPage;
import com.sch.www.ele.entity.CareUser;
import com.sch.www.ele.entity.CareUserExample;
import com.sch.www.ele.mapper.CareUserMapper;
import com.sch.www.ele.services.CareUserServices;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class CareUserServicesImpl extends BaseServicesSimpleImp<CareUser, CareUserExample, CareUserMapper, CareUserServices> implements CareUserServices {
    @Override
    protected CareUserExample getExampleNewInstance() {
        return new CareUserExample();
    }

    @Override
    protected String getTableName() {
        return null;
    }

    @Override
    public CareUser getByAccountId(String accountId) {
        if (StringUtils.isBlank(accountId)) {
            return null;
        } else {
            CareUserExample example = getExampleNewInstance();
            example.createCriteria().andAccountIdEqualTo(accountId);
            CareUser careUser = getMapper().selectOneByExample(example);
            return careUser;
        }
    }

    @Override
    public CustomPage<CareUser> list(String name, String idCard, String email, String phoneNumber, Byte gender, int pageNum, int pageSize) {
        CareUserExample example = getExampleNewInstance();
        CareUserExample.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotBlank(name)) {
            criteria.andNameLike(likePacking(name));
        }
        if (StringUtils.isNotBlank(idCard)) {
            criteria.andIdCardLike(likePacking(idCard));
        }
        if (StringUtils.isNotBlank(email)) {
            criteria.andEmailLike(likePacking(email));
        }
        if (StringUtils.isNotBlank(phoneNumber)) {
            criteria.andPhoneNumberLike(likePacking(phoneNumber));
        }
        if (gender != null) {
            criteria.andGenderEqualTo(gender);
        }
        return getMapper().selectByExampleStartPage(example, pageNum, pageSize);
    }
}
